package com.mp.approvalreq.entity;

import com.alibaba.fastjson.JSONObject;
import com.mp.user.entity.User;
import com.plusmoney.util.Utils;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class TemplateFolder {

    private Integer id;

    private Integer companyId;

    private String name;

    private String color;

    private Integer sort;

    private List<Integer> templates;

    private User user;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getCompanyId() {
        return companyId;
    }

    public void setCompanyId(Integer companyId) {
        this.companyId = companyId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public List<Integer> getTemplates() {
        return templates;
    }

    public void setTemplates(List<Integer> templates) {
        this.templates = templates;
    }

    public void setTemplates(String templates) {
        if (StringUtils.isNotEmpty(templates)) {
            this.templates = JSONObject.parseArray(templates, Integer.class);
        }
    }

    public void addTemplate(Integer templateAncestorId) {
        if (Utils.isEmpty(this.templates)) {
            this.templates = new ArrayList<>();
        } else {
            if (this.templates.contains(templateAncestorId)) {
                return;
            }
        }
        this.templates.add(templateAncestorId);
    }

    public void removeTemplate(Integer templateAncestorId) {
        if (Utils.isEmpty(this.templates)) {
            return;
        }
        this.templates.remove(templateAncestorId);
    }


    public boolean includeTemplate(Template template) {
        return Utils.isNotEmpty(templates) && templates.contains(template.getAncestorId());
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }
}
